c# base vs this

71

c# base vs this -

// The 'this' keyword represents the current class instance.
// While 'base' access's a method on the parent.

// Example of usage:
public class Parent
{
    public virtual void Foo() {}
}

public class Child : Parent // Derive from 'Parent' class
{
    public override void Foo()
    { base.Foo(); } // call the virtual method on 'Parent'

	// The override is basically not doing anything in this case, since we do
	// exactly the same thig as in the parent method (which in this case is nothing).
}

Comments

Submit
0 Comments